import { Logger } from "./Logger";

export class BundleManager {

    public static instance: BundleManager = new BundleManager();

    
    public bundleName_main: string = "main"
    // public bundleName_doudizhu: string = "doudizhu"
    // public bundleName_majiang: string = "majiang"
    // public bundleName_hz_mj: string = "hz_mj"

    public bundleNameList: Array<string> = [
        // "doudizhu",
        // "majiang",
        // "hz_mj"
    ]

    public bundleMap: Map<string, cc.AssetManager.Bundle> = new Map<string, cc.AssetManager.Bundle>()

    public loadBundle(bundleName: string): Promise<void> {
        Logger.log("loadBundle=====", bundleName)
        return new Promise((resolve, reject) => {
            cc.assetManager.loadBundle(bundleName, (err: Error, bundle: cc.AssetManager.Bundle) => {
                Logger.log("loadBundle==complete===", err, bundle)
                if (err) {
                    reject()
                } else {
                    this.bundleMap.set(bundleName, bundle);
                    resolve();
                }
            });
        })
    }
}